"""

"""

import abc as abc_module

###############################################################################
# Module Exceptions

class ModuleException(Exception): pass
class ModuleError(ModuleException): pass

###############################################################################
# Primary Class

class Dictable(object):
    __metaclass__ = abc_module.ABCMeta
    # DICT_MAPPING = {}

    @abc_module.abstractmethod
    def to_dict(self):
        "handle dynamic generation of dict...?"
    

def dictable(cls):
    # find keys for dict from __init__
    cls.to_dict = lambda self: dict(
            zip(keys, (getattr(self, key) for key in keys)),
            )
    Dictable.register(cls)
    return keys

#class DefaultDictable(Dictable): # decorator?
#    def _init__(self, **kwargs):
#        for key in kwargs:
#            setattr(self, key, kwargs[key])
#        self._keys = kwargs.keys()
#    def to_dict(self):
#        return dict(zip(
#                self._keys, 
#                (getattr(self, key) for key in self._keys),
#                ))


def with_param_mapping(name, target, transformation=None):
    # stack them up
    # check if name already taken?
    # check if target in original function?
    def decorator(func):
        def new_func(*args, **kwargs):
            if name in kwargs:
                value = kwargs[name]
                if transformation:
                    value = transformation(value)
                kwargs[target] = value
                del kwargs[name]
            return func(*args, **kwargs)
        return new_func
    return decorator

                    
